#include <iostream>
using namespace std;

int main() {

	int n;	
	while(cin>>n){
		int ret=1;
		while(ret<=n){
			ret<<=1;
		}
		cout<<(ret>>1)-1<<endl;;
	}
	
	return 0;
}
/*
0 1 2 3 4 5 6 7

1 3 5 7			2
3 7				4	
7				


*/
